package cn.jinjie.day10;

public class Test02 {
    public static void main(String[] args) {
        try {
            saveAge(-10);
            saveAge(100);
            saveAge(150);
        } catch (AgeIllegalException e) {
            System.out.println(e.getClass().getName());//异常类的信息
            System.out.println(e.getMessage());//异常信息描述
            //异常出的具体位置信息
            for (StackTraceElement ste : e.getStackTrace()) {
                System.out.println(ste);
            }
            // System.out.println(e.getStackTrace());
        }
    }

    /**
     *
     * @param age
     * @throws AgeIllegalException
     */

    public static void saveAge(int age) throws AgeIllegalException {
        if (age < 0 || age > 150) {
            throw new AgeIllegalException("age error" + age);
        }
        System.out.println("保存年龄" + age);

    }
}
